package com.fishery.processing.mapper;

import com.fishery.processing.entity.ProductBatch;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fishery.processing.entity.vo.BeforeMessageVo;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author run
 * @since 2021-03-12
 */
public interface ProductBatchMapper extends BaseMapper<ProductBatch> {

    @Update("UPDATE FORM t_processing_product_batch SET weight = weight - #{weight} WHERE id = #{batchId} AND weight >= #{weight}")
    public int setInventoryOfBatch(String batchId, Double weight);

    @Select("SELECT tpmi.material_id AS product_id, tpmi.supplier_type AS source_type FROM t_processing_product_batch tppb " +
            "INNER JOIN t_processing_job tpj INNER JOIN t_processing_material_inventory tpmi ON tppb.id = #{batchId} " +
            "AND tppb.job_id = tpj.id AND tpj.material_id = tpmi.material_id")
    public BeforeMessageVo getBeforeMessageOfBatch(String batchId);

}
